<template>
    <div>
        <Header></Header>
        <div>
            <group>
                <x-input title="用户名" label-width="80px" v-model="findForm.userName" required   placeholder="请输入用户名"></x-input>               
                <x-input title="邮箱" label-width="80px" v-model="findForm.userEmail" is-type="email" required placeholder="请输入邮箱"></x-input> 
            </group>
            <div style="padding:20px;"> 
                <x-button type="warn" @click.native="findPwd">找回密码</x-button>
            </div>
        </div>
        <Footer></Footer>
    </div>
</template>

<script>
import Header from '@/components/commons/header/header'
import Footer from '@/components/commons/footer/footer'
import userController from '@/api/userController/index'
import USER from '@/utils/user'
    export default {
        name:'findPassWordCode',//找回密码
        data(){
            return {
                userInfo: null,
                findForm:{
                    userName:null,
                    userEmail:null
                }
            }
        },
        created(){
          },
          components:{Header,Footer},
        methods:{  
            findPwd(){
                //验证form
                if(!this.findForm.userName){
                    this.$vux.toast.show({
                        text: '请输入用户名',
                        type:'warn'
                  })
                    return false
                }
                if(!this.findForm.userEmail){
                    this.$vux.toast.show({
                        text: '请输入邮箱',
                        type:'warn'
                  })
                    return false
                }  
                var reg = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
                if(!reg.test(this.findForm.userEmail)){
                    this.$vux.toast.show({
                        text: '邮箱格式不正确',
                        type:'warn'
                    })
                    return false
                }                                            
                var formData  = this.findForm;
                userController.findPwd(formData).then(response=>{
                    if(response.success){
                        this.$vux.toast.show({
                            text: response.msg,
                            type:'success'
                        })
                    }else{
                          this.$vux.toast.show({
                            text: response.msg,
                            type:'warn'
                        })
                    }
                })
            } 
        }              
    }
</script>

<style scoped>

</style>